package com.t21;

import static net.mindview.util.Print.print;

/**
 * Created by xuyiwei on 2018/9/16.
 */
class DualSynch{
    private Object syncObject = new Object();
    public synchronized void f(){
        for(int i=0;i<5;i++){
            print("f()");
            Thread.yield();
        }
    }
    public void g(){
        synchronized (this){
            for(int i=0;i<5;i++){
                print("g()");
                Thread.yield();
            }
        }
    }
}
public class SyncObject {
    public static void main(String[] args) {
        final DualSynch ds = new DualSynch();
        new Thread(){
            public void run(){
                ds.f();
            }
        }.start();
        ds.g();
        /**
         * g()
         f()
         g()
         f()
         g()
         f()
         g()
         f()
         g()
         f()

         */
    }
}
